info = []


def add_info():
    """添加学员"""
    new_id = input("请输入学号：")
    new_name = input("请输入姓名：")
    new_tel = input("请输入电话号码：")

    global info

    for i in info:
        if new_name == i["name"]:
            print("用户已存在")
            break

    info_dict = {"id": new_id, "name": new_name, "tel": new_tel}

    info.append(info_dict)

    print(info)


def del_info():
    """删除学员"""
    while True:
        del_id = int(input('请输入要删除的学员学号：'))

        global info

        if 0 <= del_id < len(info):
            del_flag = input('确定要删除吗？yes or no')
            if del_flag == 'yes':
                del info[del_id]
            print(info)
            break
        else:
            print('输入信息有误，请重新输入')


def modify_info():
    """修改学员信息"""
    while True:
        modify_num = int(input("请输入要修改的学员学号："))

        global info

        if 0 <= modify_num < len(info):
            print(f"该学员学号是{info[modify_num]["id"]},姓名是{info[modify_num]["name"]}，手机号{info[modify_num]["tel"]}")
            info[modify_num]['id'] = input("请输入学号：")
            info[modify_num]['name'] = input("请输入姓名：")
            info[modify_num]["tel"] = input("请输入手机号")
            print(info)
            break
        else:
            print("输入的学号有误，请重新输入")


def search_info():
    """查询学员信息"""
    search_name = input("请输入要查询的学员的名字：")

    for i in info:
        if search_name == i['name']:
            print("***查询到的信息如下***")
            print(f"该学员学号是{i["id"]},姓名是{i["name"]},电话号是{i["tel"]}")
            break
        else:
            print("查无此人……")


def print_all():
    """显示所有学员信息"""
    print('学号\t姓名\t手机号\t')
    for i in info:
        print(f"{i['id']}\t{i['name']}\t{i['tel']}\t")



